﻿using System;

namespace LocationAwareness
{
    public class GPSUrl
    {
        private string serviceUrl;
        private string detailFile;
        private string updateDetailFile;
        private string defaultFile;
        private double latitude;
        private double longtitude;
        private string objectID;

        /// <summary>
        /// Constructor for a GPSUrl Object
        /// </summary>
        /// <param name="webServiceUrl">
        /// Url under wich the service is reachable
        /// </param>
        public GPSUrl(String webServiceUrl)
        {
            serviceUrl = webServiceUrl;
            latitude = 0;
            longtitude = 0;
            detailFile = "";
            defaultFile = "";
        }

        /// <summary>
        /// URL of the Server providing LocAwa
        /// </summary>
        public string ServiceUrl
        {
            get
            {
                return serviceUrl;
            }

            set
            {
                serviceUrl = value;
            }
        }

        /// <summary>
        /// Specifies the file on the webserver the application connects to for the detail view.
        /// The string has to contain the substrings "{0}", "{1}" and "{2}".
        /// "{0}" will be replaced by the actual value of gps latitude.
        /// "{1}" will be replaced by the actual value of gps longtitude.
        /// "{2}" will be replaced by the value of the ID from the object, wich will be shown. 
        /// </summary>
        public string DetailFile
        {
            set
            {
                detailFile = value;
            }

            get
            {
                return detailFile;
            }
        }

        /// <summary>
        /// Specifies the file on the webserver the application connects to for the detail view.
        /// The string has to contain the substrings "{0}", "{1}" and "{2}".
        /// "{0}" will be replaced by the actual value of gps latitude.
        /// "{1}" will be replaced by the actual value of gps longtitude.
        /// "{2}" will be replaced by the value of the ID from the object, wich will be shown. 
        /// </summary>
        public string UpdateDetailFile
        {
            set
            {
                updateDetailFile = value;
            }

            get
            {
                return updateDetailFile;
            }
        }

        /// <summary>
        /// Specifies the file on the webserver the application connects to for the default view.
        /// The string has to contain the substrings "{0}" and "{1}".
        /// "{0}" will be replaced by the actual value of gps latitude.
        /// "{1}" will be replaced by the actual value of gps longtitude.
        /// </summary>
        public string DefaultFile
        {
            set
            {
                defaultFile = value;
            }

            get
            {
                return defaultFile;
            }
        }

        /// <summary>
        /// Longtitude value to be parsed in GPS-URL
        /// </summary>
        public double Longtitude
        {
            set
            {
                longtitude = value;
            }
        }

        /// <summary>
        /// Latitude value to be parsed in GPS-URL
        /// </summary>
        public double Latitude
        {
            set
            {
                latitude = value;
            }
        }
        
        /// <summary>
        /// Object id of the poi selected for detail view.
        /// </summary>
        public string ObjectID
        {
            set
            {
                objectID = value;
            }
        }

        /// <summary>
        /// GpsPosition to be parsed in GPS-URL
        /// </summary>
        public GpsPosition Position
        {
            set
            {
                latitude = value.Latitude;
                longtitude = value.Longitude;
            }
        }

        /// <summary>
        /// URL for the webserver, with the actual GPS data for the detail view.
        /// </summary>
        /// <returns>
        /// Actual URL with GPS data for the detail view.
        /// </returns>
        public Uri getGpsUrlDetail()
        {
            string s = String.Format(serviceUrl + "/" + detailFile, latitude, longtitude, objectID);
            return new Uri(String.Format(serviceUrl + "/" + detailFile, latitude, longtitude, objectID)); 
        }

        /// <summary>
        /// URL for the webserver, with the actual GPS data for the detail view.
        /// </summary>
        /// <returns>
        /// Actual URL with GPS data for the detail view.
        /// </returns>
        public Uri getGpsUrlUpdateDetail()
        {
            string s = String.Format(serviceUrl + "/" + updateDetailFile, latitude, longtitude, objectID);
            return new Uri(String.Format(serviceUrl + "/" + updateDetailFile, latitude, longtitude, objectID));
        }

        /// <summary>
        /// URL for the webserver, with the actual GPS data for the default view.
        /// </summary>
        /// <returns>
        /// Actual URL with GPS data for the default view.
        /// </returns>
        public Uri getGpsUrlDefault()
        {
            string s = String.Format(serviceUrl + "/" + defaultFile, latitude, longtitude);
            return new Uri(String.Format(serviceUrl + "/" + defaultFile , latitude, longtitude)); 
        }
    }
}
